#pragma once
#include "SimpleCanvas.h"
#include "View.h"
#include "lang/String.h"
#include "Theme.h"
#include <vector>
#include "include/core/SkFont.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkFontMetrics.h"

namespace yzrilyzr_simplecanvas{
	ECLASS(TextView, public View){
	private:
	SkColor textColor;
	std::string text;
	std::vector<std::string> splited;
	SkFont font;
	public:
	TextView();

	void onMeasure(MeasureSpec & widthMeasureSpec, MeasureSpec & heightMeasureSpec) override;
	void setText(const std::string & str);
	const std::string & getText() const;
	void setTextSize(float size);
	void setTextColor(SkColor color);
	void onDraw(SkCanvas & canvas) override;
	private:
	// 测量文本宽度
	float measureText(const yzrilyzr_lang::String & s, u_index end);
	// 分割文本为多行
	void splitText(const yzrilyzr_lang::String & lorem, float wLimit);
	// 分割单行文本
	void splitLine(const yzrilyzr_lang::String & line, float wLimit);
	// 使用二分查找找到合适的分割点
	int getSplitIndexFine(float wLimit, const yzrilyzr_lang::String & input);
	// 找到合适的分割位置（不在单词中间分割）
	int getSplitPoint(const yzrilyzr_lang::String & input, int index);
	};
}